<?php 
	$q  = strip_tags($_GET['q']);
	$q	= trim($q);
	if(!$q){
		return false;
	}
	
	$fl = "`title` LIKE '%$q%' OR `description` LIKE '%$q%' OR `keyword` LIKE '%$q%'  OR `price` LIKE '%$q%'  OR `season` LIKE '%$q%'  OR `brand_title` LIKE '%$q%'";
	list($sql,$all_page) = splitPage("`v_product`","$fl ORDER BY `date` DESC", 30, $_GET['p']);
	$p = $_GET['p'] ? $_GET['p'] <= $all_page ?  $_GET['p'] : $all_page : 1;
 
	$strPage = fetchPage($all_page,$p,"?q=".$q,'&');
	$query = mysql_query($sql);
	$tp->Block('result');
	while($result = mysql_fetch_assoc($query)){
		$title 		= hilight(strip_tags($result['title']), $q);
		$description= strip_tags($result['description']);
		$price		= $result['price'];
		$url		= $result['url'];
		$brand_url	= $result['brand_url'];
		$thumb		= $result['thumb'] ? " <img src=\"/thumb/158/100/zc/contents/product/{$result['thumb']}\" />" : '';
		$tp->Apply();
	}
	
	$cnt_result = $title ? "$p-$all_page of $all_page" : 'No';


	function hilight($str, $q){
		if(strlen($str)<2){
			return $str;
		}
		$q_pattern  = ucfirst($q).'|'.strtolower($q).'|'.strtoupper($q).'|'.ucwords($q);
		return preg_replace_callback("/$q_pattern/", 'callback', $str);
	}
	function callback($matches) {
		return '<span class="match">'.$matches[0].'</span>';
	}
?>